package com.comum.javahomework420242025.repository;

import com.comum.javahomework420242025.pojo.PayPhase;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface PayPhaseRepository extends JpaRepository<PayPhase,Long> {
    @Query("select p from payphase p where " +
            "p.contractid=:contractid")
    List<PayPhase> findAllByContractid(String contractid);

    @Query("select p from payphase p where " +
            "cast(p.contractid as string) like %:str% or p.name like %:str% or " +
            "p.contract.name like %:str% or p.name like %:str% or " +
            "p.paytime like %:str% or " +
            "cast(p.oughtpay as string) like %:str% or " +
            "cast(p.paypay as string) like %:str% or " +
            "p.oughttime like %:str% or p.paytime like %:str%")
    Page<PayPhase> getPayPhases(String str, Pageable pageable);
    @Query("select p from payphase p where " +
            "cast(p.id as string) like %:str% or cast(p.contractid as string) like %:str% or " +
            "p.contract.name like %:str% or " +
            "p.contract.quote.chance.clientCompany.clientcompanyname like %:str% or " +
            "cast(p.contract.quote.chance.clientcompanyid as string) like %:str% or " +
            "p.name like %:str% or cast(p.oughtpay as string) like %:str% or " +
            "p.oughttime like %:str% or cast(p.paypay as string) like %:str%")
    Page<PayPhase> getPayPhasesForInquiry(String str, Pageable pageable);
    @Query("select p from payphase p where " +
            "p.contractid=:id and p.paypay > 0.00 ")
    List<PayPhase> findAllByContractidAndPayPay(String id);
}
